package models.shop;

import models.shop.pk.OrderItemPK;
import play.db.jpa.GenericModel;

import javax.persistence.*;

@Entity
@Table(name = "order_items")
public class OrderItem extends GenericModel {
    @EmbeddedId
    public OrderItemPK orderItemPK;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "productId", updatable = false, insertable = false)
    public Product product;

    @Transient
    public int getProductId(){
        return product.id;
    }
    @Transient
    public String getTitle(){
        return product.title;
    }
    @Transient
    public double getSubtotal(){
        return quantity*unitPrice;
    }
    public int quantity;
    public double unitPrice;
}
